<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;
use yii\helpers\ArrayHelper;
use kartik\select2\Select2;
use yii\web\JsExpression;

/* @var $this yii\web\View */
/* @var $searchModel common\models\kingdee\HrEmpLaborRelationSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('kingdee', 'Hr Emp Labor Relations');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hr-emp-labor-relation-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Hr Emp Labor Relation'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
        'pager' => [
//            'class'          => GoPager::className(),
            'nextPageLabel'  => Yii::t('app', 'Next Page'),
            'prevPageLabel'  => Yii::t('app', 'Previous Page'),
            'firstPageLabel' => Yii::t('app', 'First Page'),
            'lastPageLabel'  => Yii::t('app', 'Last Page'),
            'options' => [
                'class' => 'pagination pagination-sm m-t-none m-b-none',
            ],
        ],
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                'class' => 'yii\grid\SerialColumn',
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
            ],


            [
                'label' => Yii::t('app', 'Employee'),
                'attribute' => 'FPERSONID',
                'value' => function ($model) {
                    return Html::a(EhrHelper::getPersonNameById($model['FPERSONID']), [
                        '/kingdee/person/view',
                        'id' => $model['FPERSONID'],
                    ],
                        ['target' => '_blank']);
                },
                'format' => 'raw',
                'filter' => Select2::widget([
                    'model' => $searchModel,
                    'attribute' => 'FPERSONID',
                    'options' => [
                        'class' => 'form-control drop-search',
                        'placeholder' => Yii::t('app', \common\consts\CommonResources::PROMPT_PLS_SELECT()),
                    ],
                    'pluginOptions' => [
                        'minimumInputLength' => 1,
                        'allowClear' => true,
                        'language' => [
                            'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                        ],
                        'ajax' => [
                            'url' => '/kingdee/person/json-all',
                            'dataType' => 'json',
                            'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                        ],
                        'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                        'templateResult' => new JsExpression('function(res) { return res.text; }'),
                        'templateSelection' => new JsExpression('function (res) { return res.text; }'),
                    ],
                ]),
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 200px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 200px;'],
            ],
//            'FEFFDT',
//            'FLEFFDT',
            [
                'label' => Yii::t('app', 'Valid Date'),
                'attribute' => 'FEFFDT',
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
            ],

            [
                'label' => Yii::t('app', 'Expire Date'),
                'attribute' => 'FLEFFDT',
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
            ],
//            'FHISTORYRELATEID',
            [
                'label' => Yii::t('app', 'Person Department'),
                'attribute' => 'FCORPORATEUNITID',
                'value' => function ($model) {
                    return Html::a(EhrHelper::getOrgAdminById($model['FCORPORATEUNITID']), [
                        '/kingdee/org-admin/view',
                        'id' => $model['FCORPORATEUNITID'],
                    ],
                        ['target' => '_blank']);
                },
                'format' => 'raw',
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
            ],
            [
                'attribute' => 'FLABORRELATIONSTATEID',
                'label' => Yii::t('app', 'Labor Relation State'),
                'value' => function ($model) {
                    return EhrHelper::getHrEmployeeTypeById($model['FLABORRELATIONSTATEID']);
                },
                'filter' => ArrayHelper::map(\common\models\kingdee\HrEmployeeType::find()->all(), 'FID', 'FNAME_L2'),
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
            ],
            [
                'attribute' => 'FLABORRELATIONTYPE',
                'label' => Yii::t('app', 'Labor Relation Type'),
                'value' => function ($model) {
                    return EhrHelper::getWorkRelationByIntValue($model['FLABORRELATIONTYPE']);
                },
                'filter' => EhrHelper::getWorkRelation_map(),
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
            ],

//            'FFLOWINAFFAIRID',
//             'FCREATORID',
//             'FCREATETIME',
//             'FLASTUPDATEUSERID',
//             'FLASTUPDATETIME',
//             'FCONTROLUNITID',
//             'FID',
            [
                'attribute' => 'FEMPLOYEEMODLEID',
                'label' => Yii::t('app', 'Employee Modle'),
                'value' => function ($model) {
                    return EhrHelper::getEmployeeModalById($model['FEMPLOYEEMODLEID']);
                },
                'filter' => ArrayHelper::map(\common\models\kingdee\EmployeeModle::find()->all(), 'FID', 'FNAME_L2'),
                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
